#!/bin/sh

#下载规则文件
wget --no-check-certificate -qO- https://raw.githubusercontent.com/vokins/yhosts/master/dnsmasq/union.conf|grep '0.0.0.0'|sed 's/address=\/.//g'|sed 's/\/0.0.0.0//g' >/tmp/ad1.conf
wget --no-check-certificate -qO - https://easylist-downloads.adblockplus.org/easylistchina+easylist.txt|grep ^\|\|[^\*]*\^$ |sed 's/||//g'|sed 's/\^//g' >/tmp/ad2.conf
wget --no-check-certificate -qO- http://www.malwaredomainlist.com/hostslist/hosts.txt|sed -e '/localhost/d'|grep '127.0.0.1'|sed 's/127.0.0.1  //g' >/tmp/ad3.conf 
wget --no-check-certificate -qO- https://raw.githubusercontent.com/vokins/yhosts/master/hosts.txt|sed -e '/XiaoQiang/d'|sed -e '/localhost/d'|grep '127.0.0.1'|sed 's/127.0.0.1 //g' >/tmp/ad4.conf

#合并、修正规则
cat /tmp/ad1.conf /tmp/ad2.conf /tmp/ad3.conf /tmp/ad4.conf /etc/adblock.sh/blacklist|sed -e '/[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}/d'|sort|uniq > /tmp/ad.conf
cat /tmp/ad.conf |sed -e '/#/d'|sort | uniq -u > /tmp/noad.conf
cat /tmp/noad.conf|sed 's/^/address=\/&/g'|sed 's/$/&\/127.0.0.1/g'| tr -d "\r" >/tmp/adad.conf
rm -f /tmp/ad.conf /tmp/ad1.conf /tmp/ad2.conf /tmp/ad3.conf /tmp/ad4.conf /tmp/noad.conf
